package tech.aistar.exception;

import org.springframework.lang.Nullable;
import org.springframework.ui.Model;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LogginExceptionResolver implements HandlerExceptionResolver {
    @Nullable
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @Nullable Object o, Exception e) {

        LogginException ex=null;
        if(e instanceof  LogginException){
ex= (LogginException) e;
        }else{
            ex=new LogginException("未知的错误");
        }

        System.out.println(ex.getMessage());
       System.out.println("发生错误");
        ModelAndView model=new ModelAndView();
        model.addObject("msg",ex.getMessage());
        model.setViewName("exception/5xx");
        return model;
    }
}
